package cn.okcmd.log_slf4j.bridges;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import java.util.logging.Level;
import java.util.logging.LogManager;

/**
 * create by caoqg on 2021/7/15
 * 功能说明:
 */
public class Jul_to_slf4j {
    public static void main(String[] args) {

        System.out.println("jul bridge slf4j flag:"+SLF4JBridgeHandler.isInstalled());
        //下边这两句需要执行以下
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        System.out.println("jul bridge slf4j flag:"+SLF4JBridgeHandler.isInstalled());

        Logger log1 = LoggerFactory.getLogger(Jul_to_slf4j.class);
        log1.warn("this is log by slf4j,{}","msg1_1");
        log1.info("this is log by slf4j,{}","msg1_2");
        log1.debug("this is log by slf4j,{}","msg1_3");


        java.util.logging.Logger log2 = java.util.logging.Logger.getLogger(Jul_to_slf4j.class.getName());

        //jul info 日志正常桥接
        log2.log(Level.WARNING,"this is jul_log bridge to slf4j, {0}",new Object[]{"msg2_1"});
        log2.log(Level.INFO,"this is jul_log bridge to slf4j, {0}",new Object[]{"msg2_2"});
        //jul info级别以下的日志没有输出 因为jul 日志默认级别为 info
        log2.log(Level.CONFIG,"this is jul_log bridge to slf4j but not show, {0}",new Object[]{"msg2_3"});


        System.out.println(log2.getLevel());
        System.out.println(java.util.logging.Logger.getLogger(Logger.ROOT_LOGGER_NAME).getLevel());
    }
}
